package com.etc.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.etc.entity.Jonseeker;
import com.etc.entity.User;
import com.etc.service.JonseeService;
import com.etc.service.UserService;

@Controller
public class JonseeController {
	
	@Autowired
	JonseeService jonservice;
	@Autowired
	UserService userService;
	
	@GetMapping("jonsee/{userId}")
	public ModelAndView getjon(@PathVariable("userId") int userId) {
		
		ModelAndView mav = new ModelAndView("personCenter");
		Jonseeker jonseeker = jonservice.getJon(userId);
		User user = userService.getUser(userId);
		mav.addObject("jonseeker", jonseeker);
		mav.addObject("user", user);
		return mav;
	}
	
	@RequestMapping(value = "jonse", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	public String updjon(@RequestParam("userName") String userName,@RequestParam("userSex") String userSex,@RequestParam("userTel") String userTel,@RequestParam("userSkill") String userSkill,@RequestParam("workExp") String workExp) {
		Jonseeker jon = new Jonseeker();
		jon.setUserId(6);
		jon.setUserName(userName);
		jon.setUserTel(userTel);
		jon.setUserSex(userSex);
		jon.setUserSkill(userSkill);
		jon.setWorkExp(workExp);
		int flag = jonservice.updatajon(jon);
		System.out.println("jon:" + jon);
		System.out.println(flag);
		return "redirect:jonsee/6";
	}
	
	
	
}
